package com.txc.books.utils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author: XCTANG
 * 计算总价
 */


public class CountUtils {

    //按时归还的价格
    public static String count(String price, String createTime, String endTime){

        BigDecimal num1 = new BigDecimal(price);
        BigDecimal num2 = new BigDecimal(createTime);
        BigDecimal num3 = new BigDecimal(endTime);
        String result = (num1.multiply(num3.subtract(num2))).toString();

        return result;
    }

    //逾期归还
    public static String count1(String price, String createTime, String endTime){

        String s = "2";
        BigDecimal num1 = new BigDecimal(price);
        BigDecimal num2 = new BigDecimal(createTime);
        BigDecimal num3 = new BigDecimal(endTime);
        BigDecimal num4 = new BigDecimal(s);
        String result = ((num1.multiply(num3.subtract(num2))).multiply(num4)).toString();

        return result;
    }

    //比较时间大小
    public static String compareTo(String endTime, String nowTime){

        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH");
        String result = "0";
        try {
            Date d1 = sd.parse(endTime);
            Date d2 = sd.parse(nowTime);
            //归还时间小于结束时间
            if (d1.compareTo(d2) == 1){
                result = "1";
            }
            //归还时间等于结束时间
            if (d1.compareTo(d2) == 0){
                result = "0";
            }
            //归还时间大于结束时间
            if (d1.compareTo(d2) == -1){
                result = "-1";
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return result;
    }
}
